using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace IFIGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Joueur : Movable
    {
        protected List<Livre> livres;
        protected const int MAX_NB_LIVRE = 100;
        protected int nb_livre = 0;
        public Joueur(Game game)
            : base(game)
        {
            // TODO: Construct any child components here
        }
        public Joueur(Game game, int _x, int _y, int _v, string _stringTexture)
            : base(game, _x, _y, _v, _stringTexture)
        {
            // TODO: Construct any child components here
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        public int getNbLivre()
        {
            return nb_livre;
        }

        public void setNbLivre(int _nb_livre)
        {
            this.nb_livre = _nb_livre;
        }

        public void removeLivreAt(int _index)
        {
            if (nb_livre <= _index)
                return;
            this.livres.RemoveAt(_index);
            nb_livre--;
        }

        public Livre getLivreAt(int _index)
        {
            if (nb_livre > _index)
            {
                return this.livres[_index];
            }
            return null;
        }

        public bool prendLivre(Livre livre)
        {
            if (nb_livre < MAX_NB_LIVRE && this.getDistanceToObject(livre) <= 100)
            {
                livre.setX(this.getX());
                livre.setY(this.getY());
                livres.Add(livre);
                nb_livre++;
                return true;
            }
            return false;
        }

        public virtual bool lancerLivre(Livre _livre, Joueur _joueur)
        {
            if (_livre.getCompetence() > 0)
                _livre.subCompetence(_livre.gotoObjectAndGetLen(_joueur));
            return true;
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
    }
}
